<?php
namespace app\api\controller\v1;
use app\common\controller\Api;


class Activity extends Api
{
    // 不需要登录和权限验证
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 获取活动详情
     */
    public function getActivityDetail()
    {
        // 获取请求参数中的活动 ID
        $id = input('id/d'); // 获取活动 ID（整数类型）

        if (!$id) {
            return json(['code' => 400, 'msg' => '缺少活动 ID']);
        }

        // 查询 eb_activity 表
        $activityDetail = model("\app\admin\model\Activity")::field('id, title as name, start_time, end_time, category, type, operator, organization')
            ->where('id', $id)
            ->whereNull('delete_time') // 确保未被伪删除
            ->find();

        if (!$activityDetail) {
            return json(['code' => 404, 'msg' => '活动不存在']);
        }

        // 格式化字段
        $activityDetail['start_time'] = date('Y.m.d H:i', strtotime($activityDetail['start_time']));
        $activityDetail['end_time'] = date('Y.m.d H:i', strtotime($activityDetail['end_time']));
        $activityDetail['description'] = "活动类别：{$activityDetail['category']} | 活动类型：{$activityDetail['type']}";

        return json([
            'code' => 200,
            'msg' => 'success',
            'data' => $activityDetail
        ]);
    }
}